package com.seafood.entity;

import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;

/**
 * 冷链异常报警实体类
 */
@Data
@EqualsAndHashCode(callSuper = true)
@Entity
@Table(name = "cold_chain_alerts")
public class ColdChainAlert extends BaseEntity {
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "cold_chain_record_id", nullable = false)
    private ColdChainRecord coldChainRecord;
    
    @NotNull(message = "报警时间不能为空")
    @Column(name = "alert_time", nullable = false)
    private LocalDateTime alertTime;
    
    @Enumerated(EnumType.STRING)
    @Column(name = "alert_type", nullable = false)
    private AlertType alertType;
    
    @Enumerated(EnumType.STRING)
    @Column(name = "severity", nullable = false)
    private Severity severity;
    
    @NotBlank(message = "报警描述不能为空")
    @Column(name = "description", nullable = false, length = 1000)
    private String description;
    
    @Column(name = "current_value", length = 100)
    private String currentValue;
    
    @Column(name = "threshold_value", length = 100)
    private String thresholdValue;
    
    @Column(name = "location", length = 500)
    private String location;
    
    @Column(name = "gps_coordinates", length = 100)
    private String gpsCoordinates;
    
    @Column(name = "is_resolved")
    private Boolean isResolved = false;
    
    @Column(name = "resolved_time")
    private LocalDateTime resolvedTime;
    
    @Column(name = "resolved_by", length = 100)
    private String resolvedBy;
    
    @Lob
    @Column(name = "resolution_notes")
    private String resolutionNotes;
    
    @Column(name = "notification_sent")
    private Boolean notificationSent = false;
    
    /**
     * 报警类型枚举
     */
    public enum AlertType {
        TEMPERATURE_HIGH,       // 温度过高
        TEMPERATURE_LOW,        // 温度过低
        HUMIDITY_HIGH,          // 湿度过高
        HUMIDITY_LOW,           // 湿度过低
        DEVICE_OFFLINE,         // 设备离线
        GPS_LOST,               // GPS信号丢失
        BATTERY_LOW,            // 电量低
        DOOR_OPENED,            // 车门打开
        VIBRATION_HIGH,         // 震动过大
        OTHER                   // 其他异常
    }
    
    /**
     * 严重程度枚举
     */
    public enum Severity {
        LOW,        // 低
        MEDIUM,     // 中
        HIGH,       // 高
        CRITICAL    // 严重
    }
}